package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TudaOrderTransfer;
import com.ruoyi.system.service.ITudaOrderTransferService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 货运中转Controller
 * 
 * @author tuda
 * @date 2023-09-22
 */
@Controller
@RequestMapping("/system/transfer")
public class TudaOrderTransferController extends BaseController
{
    private String prefix = "system/transfer";

    @Autowired
    private ITudaOrderTransferService tudaOrderTransferService;

    @RequiresPermissions("system:transfer:view")
    @GetMapping()
    public String transfer()
    {
        return prefix + "/transfer";
    }

    /**
     * 查询货运中转列表
     */
    @RequiresPermissions("system:transfer:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TudaOrderTransfer tudaOrderTransfer)
    {
        startPage();
        List<TudaOrderTransfer> list = tudaOrderTransferService.selectTudaOrderTransferList(tudaOrderTransfer);
        return getDataTable(list);
    }

    /**
     * 导出货运中转列表
     */
    @RequiresPermissions("system:transfer:export")
    @Log(title = "货运中转", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TudaOrderTransfer tudaOrderTransfer)
    {
        List<TudaOrderTransfer> list = tudaOrderTransferService.selectTudaOrderTransferList(tudaOrderTransfer);
        ExcelUtil<TudaOrderTransfer> util = new ExcelUtil<TudaOrderTransfer>(TudaOrderTransfer.class);
        return util.exportExcel(list, "货运中转数据");
    }

    /**
     * 新增货运中转
     */
    @GetMapping("/add/{id}")
    public String add(@PathVariable("id") Long id, ModelMap mmap)
    {
        mmap.put("orderId", id);
        return prefix + "/add";
    }

    /**
     * 新增保存货运中转
     */
    @RequiresPermissions("system:transfer:add")
    @Log(title = "货运中转", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TudaOrderTransfer tudaOrderTransfer)
    {
        return toAjax(tudaOrderTransferService.insertTudaOrderTransfer(tudaOrderTransfer));
    }

    /**
     * 修改货运中转
     */
    @RequiresPermissions("system:transfer:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TudaOrderTransfer tudaOrderTransfer = tudaOrderTransferService.selectTudaOrderTransferById(id);
        mmap.put("tudaOrderTransfer", tudaOrderTransfer);
        return prefix + "/edit";
    }

    /**
     * 修改保存货运中转
     */
    @RequiresPermissions("system:transfer:edit")
    @Log(title = "货运中转", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TudaOrderTransfer tudaOrderTransfer)
    {
        return toAjax(tudaOrderTransferService.updateTudaOrderTransfer(tudaOrderTransfer));
    }

    /**
     * 删除货运中转
     */
    @RequiresPermissions("system:transfer:remove")
    @Log(title = "货运中转", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tudaOrderTransferService.deleteTudaOrderTransferByIds(ids));
    }

    @RequiresPermissions("system:transfer:add")
    @Log(title = "新增中转", businessType = BusinessType.INSERT)
    @PostMapping( "/addOrderT")
    @ResponseBody
    public AjaxResult addOrderT(String orderId)
    {
        TudaOrderTransfer tudaOrderTransfer = new TudaOrderTransfer();
        tudaOrderTransfer.setOrderId(Long.valueOf(orderId));
        return toAjax(tudaOrderTransferService.insertTudaOrderTransfer(tudaOrderTransfer));
    }


    /**
     * 更新中转信息
     */
    @Log(title = "更新中转信息", businessType = BusinessType.UPDATE)
    @PostMapping( "/updateOrderTransfer")
    @ResponseBody
    public AjaxResult updateOrderTransfer(Long id, String tName, String tValue)
    {
        return toAjax(tudaOrderTransferService.updateOrderTransfer(id, tName, tValue));
    }
}
